package t.com.model;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import okhttp3.Call;
import okhttp3.Response;
import t.com.base.BaseNewsModel;
import t.com.bean.NewResultBean;
import t.com.bean.NewsBean;
import t.com.util.GsonResultUtils;
import t.com.util.HttpUtil;

/**
 * @author：zcx
 * @date:on 2018/2/28 0028 16:18
 */

public class INewsModel implements BaseNewsModel {
    @Override
    public void loadData(final loadOnListener listener) {
        HttpUtil.sendOkHttpPostRequest("http://192.168.3.18:8000/api/Config/GiftItem",new okhttp3.Callback(){
            @Override
            public void onFailure(Call call, IOException e) {

            }

            @Override
            public void onResponse(Call call, Response response) throws IOException {
                String responseData = response.body().string();
                final List<NewsBean> beanList = new ArrayList<>();
                NewResultBean bean = GsonResultUtils.getResultData(responseData,NewResultBean.class);
                for (int i=0;i<bean.getData().getList().size();i++) {
                    beanList.add(bean.getData().getList().get(i));
                }
                listener.onComplete(beanList);
            }
        });
    }
}
